package se.chalmers.tda366.crumble.gui.components;

import java.awt.Color;
import java.awt.Component;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import se.chalmers.tda366.crumble.core.IArticle;



public class LatestArticlesPanel extends JPanel {
	
	private List<IArticle> articleList;
	
	public LatestArticlesPanel(List<IArticle> list){
		articleList=list;
		
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		this.setBackground(Color.white);
		this.setBorder(new LineBorder(Color.black, 1));
		
		this.add(new JLabel("Latest articles"));
		
		for(IArticle a:articleList){
			String time=a.getDateString();
			int index=time.indexOf(":");
			if(index>=0)
			{
				time=time.substring(index-2, index+3);	
			}
			else
			{
				time = "00:00";
			}
			ArticleListItem temp = new ArticleListItem(time + " " + a.getHeadline(), a);
			temp.setAlignmentX(Component.LEFT_ALIGNMENT);
			this.add(temp);

		}
	}
}
